UFC from 1998 - 2021

What was I looking to find?

How will this be looked at?

Strike attempts per minute for top five strikers

column

Column

Strike attempts per minute for Top Five Grapplers

column

Column

Take Down Average for Top Five Strikers

column

Column

Take Down Average for Top Five Grapplers

column

Column

Record for Top Five Strikers

column

Column

Record for Top Five Grapplers

column

Column

Anderson Silva Record After Turning 35

column

Column

Reach in Fights (Advantage for Red Fighter)

column

Column

Reach in Fights (Advantage for Blue Fighter)

column

Column

---
title: "UFC Final Project "
author: "Luke Keirn"
date: "2024-04-29"
output: 
  flexdashboard::flex_dashboard:
    source_code: embed
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(DT)
library(plotly)
raw_fighter_details <- read_csv("raw_fighter_details.csv")
data <- read.csv("data.csv")
```


UFC from 1998 - 2021
===

What was I looking to find? 

- What is better a striker or a wrestler?
- What external factors can influence the result of a UFC fight?

How will this be looked at?

- Strike Attempts 
- Take Down Average
- Overall Records
- Age 
- Reach

Strike attempts per minute for top five strikers 
===

- More than two strikes per minute
- Five minutes per Round
- Three to five rounds 
- 50 or more per fight

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot1, fig.align= 'center', out.width="100%"}
library(ggplot2)

selected_fighters <- c("Conor McGregor", "Anderson Silva", "Israel Adesanya", "Max Holloway", "Jose Aldo")

striker_data <- raw_fighter_details[raw_fighter_details$fighter_name %in% selected_fighters, ]

ggplot(striker_data, aes(x = fighter_name, y = SApM, fill = SApM)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.7) +
  scale_fill_gradient(low = "white", high = "blue", limits = c(1, NA)) +
  labs(x = "Fighter Names", y = "Strike Attempts Per Minute (SApM)", title = "SApM Distribution for Top 5 Strikers") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Strike attempts per minute for Top Five Grapplers 
===

- Everyone, but Daniel Cormier
- Less strikes thrown
- Less exhausting

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot2, fig.align = 'center', out.width="100%"}
library(ggplot2)

selected_wrestlers <- c("George St. Pierre", "Matt Hughes", "Randy Couture", "Daniel Cormier", "Chael Sonnen")
wrestler_data <- raw_fighter_details[raw_fighter_details$fighter_name %in% selected_wrestlers, ]

ggplot(wrestler_data, aes(x = fighter_name, y = SApM, fill = SApM)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.7) +
  scale_fill_gradient(low = "white", high = "blue", limits = c(1, NA)) +
  labs(x = "Fighter Names", y = "SApM", title = "SApM Distribution for Top 5 Grapplers") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Take Down Average for Top Five Strikers 
===

- Not even 1 per match
- Don't look for the ground

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot3, fig.align = 'center', out.width="100%"}
library(ggplot2)
selected_fighters <- c("George St. Pierre", "Matt Hughes", "Randy Couture", "Daniel Cormier", "Chael Sonnen")
striker_data <- raw_fighter_details[raw_fighter_details$fighter_name %in% selected_fighters, ]
ggplot(striker_data, aes(x = fighter_name, y = TD_Avg)) +
  geom_tile(aes(fill = TD_Avg)) +
  scale_fill_gradient(low = "white", high = "blue", limits = c(1, NA)) + 
  labs(x = "Fighter Names", y = "TD_Avg", title = "TD_Avg Heatmap for Top 5 Grapplers") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Take Down Average for Top Five Grapplers
===

- Higher average per match
- Looking for the ground 

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot4, fig.align = 'center', out.width="100%"}
library(ggplot2)
selected_fighters <- c("George St. Pierre", "Matt Hughes", "Randy Couture", "Daniel Cormier", "Chael Sonnen")
striker_data <- raw_fighter_details[raw_fighter_details$fighter_name %in% selected_fighters, ]
ggplot(striker_data, aes(x = fighter_name, y = TD_Avg)) +
  geom_tile(aes(fill = TD_Avg)) +
  scale_fill_gradient(low = "white", high = "blue", limits = c(1, NA)) + 
  labs(x = "Fighter Names", y = "TD_Avg", title = "TD_Avg Heatmap for Top 5 Grapplers") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Record for Top Five Strikers
===

- Blue = Blue Fighter
- Red = Red Fighter
- More of a mixture

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot6, fig.align = 'center', out.width="100%"}
library(ggplot2)

selected_fighters <- c("Anderson Silva", "Max Holloway", "Conor McGregor", "Israel Adesanya", "Jose Aldo")
selected_dates <- as.Date(c("2010-08-07", "2011-02-05", "2011-08-27", "2012-07-07", "2012-10-13",
                            "2013-07-06", "2013-12-28", "2015-01-31", "2016-02-27", 
                            "2016-07-09", "2017-02-11", "2019-02-09", "2019-05-11", "2020-10-03",
                            "2012-02-04", "2013-05-25", "2013-08-17", "2019-04-13", "2019-12-14",
                            "2020-07-11", "2016-03-05", "2018-10-06", "2021-01-23", 
                            "2021-03-06", "2015-12-12", "2017-06-03", "2017-12-02",
                            "2019-05-11", "2019-12-14", "2020-07-11"))

filtered_data <- data[(data$B_fighter %in% selected_fighters | data$R_fighter %in% selected_fighters) &
                        data$date %in% selected_dates, ]
filtered_data$color <- ifelse(filtered_data$date %in% c("2013-07-06", "2013-12-28", "2016-02-27", "2016-07-09", 
                                                        "2019-02-09", "2019-05-11", "2020-10-03", "2012-02-04", 
                                                        "2013-05-25", "2013-08-17", "2019-04-13", "2019-12-14", 
                                                        "2020-07-11", "2016-03-05", "2018-10-06", "2021-01-23", 
                                                        "2021-03-06", "2015-12-12", "2017-06-03", "2017-12-02",
                                                        "2019-05-11", "2019-12-14", "2020-07-11"),
                              "Red", "Blue")

ggplot(filtered_data, aes(x = date, y = Winner, color = color)) +
  geom_point() +
  scale_color_manual(values = c("Red" = "red", "Blue" = "blue")) +
  labs(x = "Date", y = "Winner", title = "Top Five Strikers Overall Record") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Record for Top Five Grapplers
===

- Blue = Blue Fighter
- Red = Red fighter
- Less mixture of colors

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r plot7, fig.align = 'center', out.width="100%"}
library(ggplot2)

selected_fighters <- c("George St. Pierre", "Matt Hughes", "Randy Couture", "Daniel Cormier", "Chael Sonnen")

selected_dates <- as.Date(c("2004-10-22", "2007-04-07", "2000-12-16", "2004-01-31", "2006-11-18", 
                            "2007-12-29", "2008-06-07", "2010-11-20", "2002-03-22", "2002-09-27", 
                            "2004-01-31", "2005-04-16", "2006-02-04", "2008-11-15", "2009-08-29", 
                            "2011-04-30", "2015-01-03", "2019-08-17", "2005-10-07", "2006-05-27", 
                            "2009-02-21", "2010-08-07", "2012-07-07", "2013-04-27", "2013-11-16"))

filtered_data <- data[(data$B_fighter %in% selected_fighters | data$R_fighter %in% selected_fighters) &
                        data$date %in% selected_dates, ]

filtered_data$color <- ifelse(filtered_data$date %in% c("2004-10-22", "2007-04-07", "2000-12-16", "2004-01-31", 
                                                        "2006-11-18", "2007-12-29", "2008-06-07", "2010-11-20", 
                                                        "2002-03-22", "2002-09-27", "2004-01-31", "2005-04-16", 
                                                        "2006-02-04", "2008-11-15", "2009-08-29", "2011-04-30", 
                                                        "2015-01-03", "2019-08-17", "2005-10-07", "2006-05-27", 
                                                        "2009-02-21", "2010-08-07", "2012-07-07", "2013-04-27", 
                                                        "2013-11-16"),
                              "Red", "Blue")

ggplot(filtered_data, aes(x = date, y = Winner, color = color)) +
  geom_point() +
  scale_color_manual(values = c("Red" = "red", "Blue" = "blue")) +
  labs(x = "Date", y = "Winner", title = "Top Five Grapplers Overall Record") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

Anderson Silva Record After Turning 35
===

- Was undefeated before 35
- 35 seems to be "cursed"
- Injuries and more happen 
- Not the only fighter 

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r bxoplot1, fig.align = 'center', out.width="100%"}
library(ggplot2)

dates <- as.Date(c("2010-08-07", "2011-02-05", "2011-08-27", "2012-07-07", "2012-10-13",
                   "2013-07-06", "2013-12-28", "2015-01-31", "2016-02-27", 
                   "2016-07-09", "2017-02-11", "2019-02-09", "2019-05-11", "2020-10-03"))


filtered_data <- data[data$B_fighter == "Anderson Silva" | data$R_fighter == "Anderson Silva", ]


filtered_data$color <- ifelse(filtered_data$date %in% dates, "Red", "Blue")

ggplot(filtered_data, aes(x = Winner, fill = color)) +
  geom_bar() +
  scale_fill_manual(values = c("Red" = "red", "Blue" = "blue")) +
  labs(x = "Winner", y = "Count", title = "Anderson Silva's Record (35 Years and Older)") +
  theme_minimal()
```

Reach in Fights (Advantage for Red Fighter)
===

- Across all weights classes 
- Red had reach advantage
- Resulted in wins

column {data-width=450}
---

Column {.tabset data-wdith=550}
---

```{r boxplot2, fig.align = 'center', out.width="100%"}
library(ggplot2)

filtered_data <- data[data$R_Reach_cms > data$B_Reach_cms, ]

win_counts <- table(filtered_data$Winner)

win_data <- data.frame(Winner = names(win_counts), Wins = as.numeric(win_counts))

ggplot(win_data, aes(x = reorder(Winner, -Wins), y = Wins, fill = Winner)) +
  geom_bar(stat = "identity") +
  labs(x = "Winner", y = "Number of Wins", title = "Red Wins With Reach Advantage") +
  theme_minimal()
```

Reach in Fights (Advantage for Blue Fighter)
===

- Across weight all classes
- Blue had reach advantage
- Did not result in wins

column {data-width=450}
---
  
Column {.tabset data-wdith=550}
---

```{r boxplot3, fig.align = 'center', out.width="100%"}
library(ggplot2)

filtered_data <- data[data$B_Reach_cms > data$R_Reach_cms, ]

win_counts <- table(filtered_data$Winner)

win_data <- data.frame(Winner = names(win_counts), Wins = as.numeric(win_counts))

ggplot(win_data, aes(x = reorder(Winner, -Wins), y = Wins, fill = Winner)) +
  geom_bar(stat = "identity") +
  labs(x = "Winner", y = "Number of Wins", title = "Blue Wins With Reach Advantage") +
  theme_minimal()
```